package com.woniuxy.factory.controller;

import com.woniuxy.factory.entity.Purchasegoods;
import com.woniuxy.factory.entity.Purchaseplan;
import com.woniuxy.factory.entity.ResponseResult;
import com.woniuxy.factory.exception.BusinessException;
import com.woniuxy.factory.service.PurchasegoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class PurchasegoodsController {
    @Autowired
    PurchasegoodsService purchasegoodsService;
    //查询采购计划项
    @GetMapping("/purchasegoods")
    @ResponseBody
    public ResponseResult<List<Purchasegoods>> getPurchasegoodsById(Purchaseplan purchaseplan, int page, int limit){
        return purchasegoodsService.getPurchasegoodsById(purchaseplan,page,limit);
    }
    //新增采购计划项

    @ResponseBody
    @PostMapping("/addpurchasegoods")
    public ResponseResult addPurchasegood(String pupId,String matId,int quantity){
        return purchasegoodsService.addPurchasegood(pupId,matId,quantity);
    }
    //删除多个计划项
    @ResponseBody
    @PostMapping("/deletepurchaseplangoods")
    public ResponseResult deletepurchaseplangoods(@RequestParam("pugIds[]")int[] pugIds){
        System.out.println(pugIds);
        try {
            return purchasegoodsService.deletepurchaseplangoods(pugIds);
        }catch (BusinessException e){
            return new ResponseResult(0,e.getMessage(),null,null);
        }
    }
}
